class Admin::SeckillSpusController < AdminController
  def index
    @seckill_spus = SeckillSpu.all
    if params[:state].presence
      @seckill_spus = @seckill_spus.where(state: params[:state])
    end
    @seckill_spus = @seckill_spus.order("created_at DESC").page(params[:page]).per(params[:per])
  end

  def show
    @seckill_spu = SeckillSpu.find params[:id]
  end

  def edit
    @seckill_spu = SeckillSpu.find params[:id]
  end

  def update
    @seckill_spu = SeckillSpu.find params[:id]
    if @seckill_spu.update seckill_spu_params
      redirect_to admin_seckill_spus_path, notice: "更新成功！"
    else
      redirect_to admin_seckill_spus_path, notice: "更新失败！"
    end
  end
  
  def destroy
    @seckill_spu = SeckillSpu.find params[:id]
    if @seckill_spu.destroy
      redirect_to admin_seckill_spus_path, notice: "删除成功."
    else
      redirect_to admin_seckill_spus_path, notice: "删除失败."
    end
  end

  private

  def seckill_spu_params
    params.require(:seckill_spu).permit(:state)
  end
end
